package com.windgo.controller.admin;

import com.windgo.bean.MarketAdminAdminListVo;
import com.windgo.bean.MarketCreateIssueVo;
import com.windgo.bean.MarketIssue;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.service.AdminService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张林浩
 * @since 2022/10/13 12:29
 */
@RestController
@RequestMapping("admin/issue")
public class AdminIssueController {
    @Autowired
    AdminService adminService;


    @RequestMapping("list")
    @RequiresPermissions("perms[admin:issue:list]")
    public BaseRespVo issueList(BasePageInfo info) {
        CommonData<MarketIssue> data = adminService.selectAllIssue(info);
        return BaseRespVo.ok(data);
    }

    @PostMapping("create")
    @RequiresPermissions("perms[admin:issue:create]")
    public BaseRespVo createIssue(@RequestBody MarketIssue marketIssue) {
        MarketCreateIssueVo marketCreateIssueVo = adminService.createIssue(marketIssue);
        return BaseRespVo.ok(marketCreateIssueVo);
    }

    @PostMapping("update")
    @RequiresPermissions("perms[admin:issue:update]")
    public BaseRespVo updateIssue(@RequestBody MarketCreateIssueVo issuePo) {
        MarketCreateIssueVo marketCreateIssueVo = adminService.updateIssue(issuePo);
        return BaseRespVo.ok(marketCreateIssueVo);
    }

    @PostMapping("delete")
    @RequiresPermissions("perms[admin:issue:delete]")
    public BaseRespVo deleteIssue(@RequestBody MarketCreateIssueVo issueBo) {
        int code = adminService.deleteIssueById(issueBo);
        if (code == 200){
            return BaseRespVo.success();
        }
        return BaseRespVo.failed1();
    }
}